home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 03 - 1987 / 03.10 Oct 87 / blast demo stuff (MPW) / Blast.p next >
Encoding:
Text File  |  1987-09-14  |  5.9 KB  |  203 lines  |  [TEXT/MPS ]

  1. UNIT Blast;
  2.  
  3. INTERFACE
  4.  
  5. USES  {$LOAD fkeyblast.dump}
  6.       MemTypes, QuickDraw, OSIntf, ToolIntf;
  7.  
  8. PROCEDURE BlastIt;
  9.  
  10. IMPLEMENTATION
  11.  
  12. PROCEDURE BlastIt;
  13. CONST
  14.   buffSize = 122; { sound mode takes 2, 20 triplets = 120 bytes }
  15. VAR
  16.   holeRgn, circleRgn : RgnHandle;
  17.   theEvent : EventRecord;
  18.   stopIt : Boolean;
  19.   whichWindow : WindowPtr;
  20.   i, dur, cnt, minSize, pictWidth, thePart :  Integer;
  21.   blastPict : Pichandle;
  22.   anotherRect, circleRect, tempRect : Rect;
  23.   mouseSpot, holeSize, middlePoint : Point;
  24.   wPort, oldPort, tempPort : GrafPtr;
  25.   DeskPattern : ^Pattern;
  26.   crossHairs, oldCursor : Cursor;
  27.   TheCurs : ^Cursor;
  28.   squareWavePtr : SWSynthPtr;
  29.   amp : integer;
  30.  
  31.   BEGIN
  32.  
  33.     { let's set up sounds... }
  34.     squareWavePtr := SWSynthPtr( NewPtr( buffSize ) );
  35.     squareWavePtr^.mode := swMode; { squarewave mode }
  36.     cnt := 400;
  37.     amp := 150;
  38.  
  39.     { 19 triplets, with decreasing pitch and volume }
  40.     FOR i := 0 TO 18 DO
  41.       WITH squareWavePtr^.triplets[ i ] DO
  42.       BEGIN
  43.         count := cnt;
  44.         amplitude := amp;
  45.         duration := 1;
  46.         cnt := cnt + 60;
  47.         amp := amp - 8;
  48.       END;
  49.  
  50.     WITH squareWavePtr^.triplets[ 19 ] DO
  51.     BEGIN
  52.       count := 0;     { quit }
  53.       amplitude := 0; { making }
  54.       duration := 0;  { sounds }
  55.     END;
  56.  
  57.     { let's put up our cursor, saving the old one first...
  58.       there is no 'GetCursor' call to complement 'SetCursor',
  59.       so we have to dip into low memory and steal it }
  60.     TheCurs := pointer( $844 );
  61.     oldCursor := TheCurs^;
  62.  
  63.     { we need to put data into our cursor variable so we
  64.       can do a 'SetCursor' call.  stuffing the data directly
  65.       into low memory doesn't work, because the cursor on the
  66.       screen wouldn't change until the mouse was moved }
  67.     StuffHex( ptr( @crossHairs ), '71C7408140810000' );
  68.     StuffHex( ptr( longint( @crossHairs ) + 8 ), '049002A041C17777' );
  69.     StuffHex( ptr( longint( @crossHairs ) + 16 ), '41C102A004900000' );
  70.     StuffHex( ptr( longint( @crossHairs ) + 24 ), '4081408171C70000' );
  71.     StuffHex( ptr( longint( @crossHairs ) + 32 ), '01C0208210840808' );
  72.     StuffHex( ptr( longint( @crossHairs ) + 40 ), '07F007F047F177F7' );
  73.     StuffHex( ptr( longint( @crossHairs ) + 48 ), '47F107F007F00808' );
  74.     StuffHex( ptr( longint( @crossHairs ) + 56 ), '1084208201C00000' );
  75.     StuffHex( ptr( longint( @crossHairs ) + 64 ), '00070008' );
  76.     SetCursor( crossHairs );
  77.  
  78.     { make the jaggy hole }                
  79.     holeRgn := NewRgn;
  80.     OpenRgn;
  81.       MoveTo( 250, 180 );
  82.       LineTo( 260, 226 );
  83.       LineTo( 230, 252 );
  84.       LineTo( 260, 242 );
  85.       LineTo( 232, 278 );
  86.       LineTo( 270, 242 );
  87.       LineTo( 286, 304 ); { basic hole design by Scott Boyd }
  88.       LineTo( 278, 234 );
  89.       LineTo( 306, 242 );
  90.       LineTo( 278, 244 );
  91.       LineTo( 314, 196 );
  92.       LineTo( 270, 216 );
  93.       LineTo( 250, 180 );
  94.     CloseRgn( holeRgn );
  95.  
  96.     { "home" the region, prepare to add a circle to the middle of the hole }
  97.     WITH holeRgn^^.rgnBBox DO
  98.       OffsetRgn( holeRgn, -left, -top );
  99.       
  100.     { calculate the size of the hole and where the middle is }
  101.     WITH holeRgn^^.rgnBBox DO
  102.     BEGIN
  103.       holeSize.h := right - left;
  104.       holeSize.v := bottom - top;
  105.       middlePoint.h := ( right - left ) DIV 2;
  106.       middlePoint.v := ( bottom - top ) DIV 2;
  107.     END;
  108.  
  109.     { figure out what size to make the circle }
  110.     IF holeSize.h > holeSize.v THEN
  111.       minSize := holeSize.h 
  112.     ELSE
  113.       minSize := holeSize.v;
  114.  
  115.     { we'll make the circle 40% of the small dimension;
  116.           minSize will be the radius of the circle }
  117.     minSize := minSize div 5;
  118.     WITH middlePoint DO
  119.       SetRect( circleRect, h - minSize, v - minSize,
  120.                            h + minSize, v + minSize );
  121.  
  122.     { make the circle }
  123.     circleRgn := NewRgn;
  124.     OpenRgn;
  125.       FrameOval( circleRect );
  126.     CloseRgn( circleRgn );
  127.  
  128.     { add the circle to the hole }
  129.     UnionRgn( holeRgn, circleRgn, holeRgn );
  130.  
  131.     { we don't need this any more... }
  132.     DisposeRgn( circleRgn );
  133.  
  134.     { make the window manager port the current port }
  135.     GetPort( oldPort );
  136.     GetWMgrPort( wPort );
  137.     SetPort( wPort );
  138.  
  139.     { ok, setup's all finished... here's the "main loop" }
  140.     stopIt := FALSE;
  141.     REPEAT
  142.  
  143.           { accept only mouseDown events }
  144.       IF GetNextEvent( mDownMask, theEvent) THEN
  145.                 BEGIN
  146.  
  147.                     { figure out where they clicked }
  148.                     thePart := FindWindow( theEvent.where, whichWindow );
  149.         
  150.           { respond only if they click on the content area of a window }
  151.                     IF (thePart = inContent) THEN
  152.                         BEGIN                
  153.  
  154.                             { Make some asynchrounous noise }
  155.                                 StartSound( Ptr( squareWavePtr ), buffSize, NIL );
  156.                                 
  157.                             mouseSpot := theEvent.where;
  158.                             
  159.                             { position the hole centered over the mouse spot }
  160.                             WITH holeRgn^^.rgnBBox DO
  161.                               OffsetRgn( holeRgn, -left, -top );
  162.                             OffsetRgn( holeRgn,
  163.                                        mouseSpot.h - holeSize.h div 2,
  164.                                                  mouseSpot.v - holeSize.v div 2 );
  165.  
  166.                             { blast a hole in the structure region }
  167.                             DiffRgn( WindowPeek( whichWindow )^.contRgn,
  168.                                      holeRgn,
  169.                                              WindowPeek( whichWindow )^.contRgn );
  170.  
  171.                             { blast a hole in the content region }
  172.               DiffRgn( WindowPeek( whichWindow )^.strucRgn,
  173.                                      holeRgn,
  174.                                              WindowPeek( whichWindow )^.strucRgn );
  175.  
  176.                             { calculate and paint all new visible regions  }
  177.                             CalcVisBehind( WindowPeek( whichWindow ), holeRgn );
  178.                             PaintBehind( windowPeek( whichWindow ), holeRgn );
  179.                             
  180.                             { and now, since 'PaintBehind' messes with the port... }
  181.                             SetPort( wPort );
  182.                         END {IF ( thePart = inContent )... }
  183.                     ELSE
  184.                         { didn't click in a window? }
  185.                         stopIt := TRUE;
  186.                 END; {IF GetNextEvent...}
  187.     UNTIL stopIt;
  188.  
  189.   { clean up the hole }
  190.     DisposeRgn( holeRgn );
  191.  
  192.   {  fix the port  }
  193.     SetPort( oldPort );
  194.  
  195.   { put the old cursor back }
  196.   SetCursor( oldCursor );
  197.   
  198.   { get rid of the sound buffer }
  199.   DisposPtr( Ptr( squareWavePtr ) );
  200.  
  201.   END; {BlastIt}
  202.  
  203. END.